package com.light.buttons;

import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.extension.physics.box2d.PhysicsWorld;
import org.anddev.andengine.input.touch.TouchEvent;
import org.anddev.andengine.ui.activity.BaseGameActivity;

import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorEvent;

import com.badlogic.gdx.math.Vector2;
import com.light.roller.BigMenu;
import com.light.roller.Direction;
import com.light.roller.Launcher;
import com.light.roller.ResourceManager;
import com.light.roller.Roller;
import com.light.roller.Roller_S3;
import com.light.roller.Roller_S4;
import com.smile.menu.MenuSpotManager;

public class ChooseMenuButton extends Button {

	private Vector2 m_spritePosition;
	private boolean isLocked = true;
	public Vector2 getSpritePosition() { return m_spritePosition; }
	public int centerX;
    public int centerY;
    int StageNum=1;
    
    private MenuSpotManager menuManager;
    
    
    
    BigMenu m_menu;
    
    public void setStageNum(int stage)
    {
    	StageNum = stage;
    }
    
    Class<?> m_stage;
	public ChooseMenuButton(MenuSpotManager menu, int positionX, int positionY, Class<?> switchStage) {
		super(menu.m_menu);
		centerX = positionX;
		centerY = positionY;
		m_stage = switchStage;
		menuManager = menu;
	}

	@Override
	public void onAccuracyChanged(Sensor sensor, int accuracy) {
		
		
	}

	@Override
	public void onSensorChanged(SensorEvent event) {

		
	}

	@Override
	public void onUpdate(float pSecondsElapsed) {
		
	}

	@Override
	public void reset() {

	}

	@Override
	public void onLoadResources() {
		if(isLocked)
		{
			ResourceManager.onLoadResources("smallRock", m_game);
			this.m_textureRegion = ResourceManager.getTextureRegion("smallRock");
		}else{
			ResourceManager.onLoadResources("StartButton", m_game);
			this.m_textureRegion = ResourceManager.getTextureRegion("StartButton");
		}
	}
	@Override
	public void unLoadResources() {
		this.m_textureRegion = null;
		ResourceManager.unLoadResources("StartButton", m_game);
	}
	
	@Override
	public void setByCameraPosition(float x, float y) {
		
		
	}

	@Override
	public void onLoadEngine() {
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public void onLoadScene(Scene scene, PhysicsWorld physicsWorld) {
		
		m_sprite = new Sprite(centerX, centerY, this.m_textureRegion)
		{
			@Override
        	public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY)
        	{
				if (isLocked == false)
				{
					if (pSceneTouchEvent.isActionDown())
					{
						//menuManager.setDestination(ChooseMenuButton.this);		
					}
					return true;
				}

				return true;
        	}
		};
		m_sprite.setScaleCenter(0, 0);
		m_sprite.setScale(0.4f);
		scene.attachChild(m_sprite);
		scene.registerTouchArea(m_sprite);
		
	}

	@Override
	public void removeFromScene(Scene scene, PhysicsWorld physicsWorld) {
		scene.unregisterTouchArea(m_sprite);
		scene.detachChild(m_sprite);

		m_sprite = null;
	}

	@Override
	public void rotate(float angle) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void initializeDirection(Direction direction) {
		// TODO Auto-generated method stub
		
	}
	
	public void setLocked(boolean locked)
	{
		isLocked = locked;
	}

}
